package com.wang.springframework.beans.factory.support;

import com.wang.springframework.beans.BeansException;
import com.wang.springframework.beans.factory.config.BeanDefinition;

/**
 * @author wangjianhua
 * @Description 自动注册的bean默认为单例模式
 * @date 2021/8/23/023 11:32
 **/
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try
        {
            bean = beanDefinition.getBeanClass().newInstance();
        }
        catch (InstantiationException | IllegalAccessException e)
        {
            throw new BeansException("Instantiation of bean failed",e);
        }

        addSingleton(beanName,bean);
        return bean;
    }
}
